<?php
namespace  zhtfrontend\components\services\customer;
use common\components\helpers\Fun;
use common\components\services\customer\Account;
use common\models\datas\DepositLog;
use zhtfrontend\models\datas\OrdersItems;
use zhtfrontend\models\datas\OrdersType;

class Opercustomer
{
    public static function InsertDeposit($model,$money,$mode=2,$deposit_id=0){
            $items = OrdersItems::find()->where(['orders_id'=>$model->id,'teach_type'=>1])->one();

            $depositModel = new DepositLog();
            $depositModel->customer_id = $model->customer_id;
            $depositModel->site_id = Fun::getSiteId();
            $depositModel->orders_id = $model->id;
            $depositModel->orders_items_id = $items->id;
            $depositModel->mode = $mode;
            $depositModel->money = $money;
            $depositModel->pay_type = 2;
            $depositModel->code = $model->sn;
            $depositModel->save(false);
            if($deposit_id > 0){
                $modelDeposit = DepositLog::findOne($deposit_id);
                if($modelDeposit != null ){
                    if($modelDeposit->money > 200){
                        //退保证金到账户
                    }
                    $modelDeposit->status = 1;
                    $modelDeposit->actual_money = $modelDeposit->money;
                    $modelDeposit->operator_id = \Yii::$app->user->id;
                    $modelDeposit->operator_name = \Yii::$app->user->identity->name;
                    $modelDeposit->application_time = time();
                    $modelDeposit->processing_time = time();
                    $modelDeposit->remarks = '保证金转到订单号为'.$model->sn;
                    $modelDeposit->processing_status = 3;
                    $modelDeposit->save(false);
                }
            }else{
                $option = [
                    'customer_id' => $model->customer_id,
                    'deposit' => $money,
                    'note'    => '缴纳保证金扣除',
                    'orders_id' => $model->id,
                    'account'  =>$money,
                    'state'   => 4
                ];
                Account::CustomerAccountReduce($option);
            }
//            if($deposit_id == 0) {
//                $option = [
//                    'customer_id' => $model->customer_id,
//                    'deposit' => $money,
//                    'note' => '缴纳保证金',
//                    'orders_id' => $model->id,
//                    'state' => 4
//                ];
//                Account::CustomerAccountIncrease($option);
//            }

    }

}